var Group = {
    template: '#group',
    methods: {
        onRefresh(done) {
            this.noMore = false
            if (this.mDbHelper == null) {
                this.mDbHelper = $.MdManager.newPageHelper($.Encryption.CloudTable.groupNumber);
            }
            this.mDbHelper.current = 1;
            this.mDbHelper.page = 20;
            that = this;
            loadMyGroup(this.mDbHelper, function(arg) {
                if (arg == null) {
                    $toast.show("加载失败");
                } else if (arg.length < 20) {
                    that.items = arg
                    that.noMore = true
                } else {
                    that.items = arg
                }
                done()
            })

        },

        onInfinite(done) {
            if (this.noMore) {
                done()
                return
            }
            if (this.mDbHelper == null) {
                this.mDbHelper = $.MdManager.newPageHelper($.Encryption.CloudTable.groupNumber);
                this.mDbHelper.page = 20;
                this.mDbHelper.current = 1;
            }
            this.mDbHelper.current += 1;

            that = this;
            loadMyGroup(this.mDbHelper, function(arg) {
                if (arg == null) {
                    $toast.show("加载失败");
                } else if (arg.length < 20) {
                    that.items.concat(arg)
                    that.noMore = true
                } else {
                    that.items.concat(arg)
                }

                done()
            })
        },
        onSearch(data) {

        },
        onItemClick(index) {
            $dialog.confirm({
                title: '提示',
                content: '选择查看内容',
                cancelText: '文章',
                okText: '组员'
            }).then((res) => {
                if (res) {

                } else {
                    this.$router.push({
                        name: 'groupMd',
                        params: {
                            groupId: this.items[index].groupId,
                            groupName: this.items[index].groupName
                        }
                    })
                }

            })

        }
    },
    data() {
        return {

            keywords: '',
            items: [],
            noMore: false,
            mDbHelper: null,
        }
    },
    beforeDestroy() {
        mapCatch.set('#group', {
            keywords: this.keywords,
            items: this.items,
            noMore: this.noMore,
            mDbHelper: this.mDbHelper,
        })
    },
    mounted() {
        let cacth = mapCatch.get('#group')
        if (cacth && cacth.items.length > 0) {
            this.keywords = cacth.keywords;
            this.items = cacth.items;
            this.noMore = cacth.noMore;
            this.mDbHelper = cacth.mDbHelper;
            return
        }
        if (this.items.length > 0) {
            return
        }
        if (this.mDbHelper == null) {
            this.mDbHelper = $.MdManager.newPageHelper($.Encryption.CloudTable.groupNumber);
            this.mDbHelper.current = 1;
            this.mDbHelper.page = 20;
            that = this;
            loadMyGroup(this.mDbHelper, function(arg) {
                if (arg == null) {
                    $toast.show("加载失败");
                } else if (arg.length < 20) {
                    that.items = arg
                    that.noMore = true
                } else {
                    that.items = arg
                }
            })
        }

    },
}